<?php
/**
 * Created by PhpStorm.
 * User: LG
 * Date: 2018/9/11
 * Time: 17:21
 */

header("content-type:text/html;charset=utf-8");         //设置编码
require_once 'Medoo.php';
require_once 'Contact.php';

/**
 * 获取监控Log GET
 * 前端入参：
 *  modularID:  模块开关ID
 */
$modularID = $_GET['modularID'];

selectState($modularID);


/**
 * @return 判断是否有该条记录
 */
function hasRecoved()
{
    global $database;
    global $modularID;
    if ($database->has("manage_monitoring_log")) {
        return true;
    } else {
        return false;
    }
}


/**
 * 查询该ID的开关状态
 */
function selectState($modularID)
{
    global $database;
    global $modularID;


/*    if (!hasRecoved()) {
        $result1 = array(
            'code' => urlencode(200),
            'msg' => urlencode('无数据'),
            'data' => null
        );
        echo urldecode(json_encode($result1));
    }*/

    $result = null;
    // 查询数据示例
    $datas = $database->select("manage_monitoring_log", [
        "log_id",
        "modular_id",
        "divice_id",
        "happen_time",
        "pic_size",
        "pic_resolution",
        "shutter_speed",
        "img",
        "is_look"
    ], [
        "modular_id[=]" => $modularID
    ]);

    $result_fi = array();
    foreach ($datas as $data) {
        $result0 = array(
            'log_id' => urlencode($data["log_id"]),
            'modular_id' => urlencode($data["modular_id"]),
            'divice_id' => urlencode($data["divice_id"]),
            'happen_time' => urlencode($data["happen_time"]),
            'pic_size' => urlencode($data["pic_size"]),
            'pic_resolution' => urlencode($data["pic_resolution"]),
            'shutter_speed' => urlencode($data["shutter_speed"]),
            'img' => urlencode($data["img"]),
            'is_look' => urlencode($data["is_look"]),
        );

        array_push($result_fi, $result0);
    }


    $result1 = array(
        'code' => urlencode(200),
        'msg' => urlencode('查询成功'),
        'data' => array_reverse($result_fi) //反转数组
    );

    echo urldecode(json_encode($result1));

}




